#文件相关操作代码示例

<<<<<<< HEAD
directory="C:\\Users\\AWA007\\Desktop\\Data\\Deng Mingzhi homework\\python-course2024\\3_Function\\File_operation\\Poem_Mao.txt"
=======
directory="File_operation\Poem_Mao.txt"
>>>>>>> upstream/master
#读取整个文件
file=open(directory,"r",encoding='utf-8')
content=file.read()
print("content=\n",content)
file.close()

#读取一行
file=open(directory,"r",encoding='utf-8')
line1=file.readline()
print("line1=\n",line1)
line1=file.readline()
print("line2=\n",line1)
file.close()

#读取多行
file=open(directory,"r",encoding='utf-8')
lines=file.readlines()
print("lines=\n",lines)
file.close()


#可迭代对象

#for line in file:
#    print(line)
#    readline=file.readline()
#   print(readline)